/*
 * @Author: 0x9DEFA478
 * @Date: 2024-01-13 21:35:38
 * @LastEditTime: 2024-02-16 00:01:43
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef hH_Concurrency_std_HPP_
#define hH_Concurrency_std_HPP_
#include <mutex>
#include <semaphore>
#include <chrono>
#include "H_Concurrency.hpp"




namespace H{

  namespace Concurrency{

#if __cplusplus >= 202000L
    class Signal_std:public SignalAbstract{

      public:
        Signal_std():S(0){}
        ~Signal_std(){}

        virtual void wait()override final{
          S.acquire();
        }

        virtual bool wait_ms(usize Timeout)override final{
          if(Timeout==0){
            return S.try_acquire();
          }
          return S.try_acquire_for(std::chrono::milliseconds(Timeout));
        }

        virtual bool wait_us(usize Timeout)override final{
          if(Timeout==0){
            return S.try_acquire();
          }
          return S.try_acquire_for(std::chrono::microseconds(Timeout));
        }

        virtual void set()override final{
          S.release();
        }

      private:
        std::binary_semaphore S;
    };

    class Lock_std:public LockAbstract{

      public:
        Lock_std(){}
        ~Lock_std(){}

        virtual void lock()override final{
          L.lock();
        }
        
        virtual void unlock()override final{
          L.unlock();
        }

      private:
        std::recursive_mutex L;
    };
#endif

  }
}




#endif //hH_Concurrency_std_HPP_
